package com.dou.ourpro.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dou.ourpro.pojo.Users;
import com.dou.ourpro.service.UsersService;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * Created with IntelliJ IDEA 2021.1 x64
 *
 * @Author: 窦义超
 * @Date: 2021/11/2021/11/11/20:53
 * @Description:
 */
@Controller
@RequestMapping("/login")
public class loginController {
    public static Users users1=new Users();
    public static Users usernames;
    @Autowired
    UsersService usersService;
    @PostMapping("login")
    public String login(Users users){
        QueryWrapper<Users> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("user_name",users.getUserName());
        queryWrapper.eq("user_password",users.getUserPassword());
        Users one = usersService.getOne(queryWrapper);
        usernames=one;
        users1.setUserName(users.getUserName());
        users1.setUserPassword(users.getUserPassword());
        List<Users> list = usersService.list();
        int count=0;
        for (int i = 0; i < list.size(); i++) {
            if(users.getUserName().equals(list.get(i).getUserName())&&users.getUserPassword().equals(list.get(i).getUserPassword())&&one.getUserGrade()>0){
                count=1;
            }
        }
        if(count==1){

            return "index1";
        }else {
            return "index";
        }

    }

}
